package com.yanqu.road.server.cmd.activity.xingyoushanshui.cross;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.XingYouShanShuiProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.PreReduceModule;
import com.yanqu.road.server.manger.activity.shanshui.XingYouShanShuiMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.Property;

@Cmd(code = Protocol.S_XING_YOU_SHAN_SHUI_RECOVER_ENERGY_FROM_CROSS,desc = "使用道具恢复体力")
public class ShanShuiRecoverEnergyFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        XingYouShanShuiProto.ShanShuiRecoverEnergyRsp rep = XingYouShanShuiProto.ShanShuiRecoverEnergyRsp.parseFrom(packet.getBytes());

        Property consume = new Property();
        consume.addProperty(XingYouShanShuiMgr.getConfig().getSHANSHUI_TIPS_ID(), rep.getUseNum());

        // 预扣除
        player.getModule(PreReduceModule.class).restorePreReduce(consume);

        if(rep.getRet() == 0){
            player.getModule(CurrencyModule.class).removeCurrency(consume, eLogMoneyType.XingYouShanShuiActivity, eLogMoneyType.XingYouShanShuiEnergyConsume);

        }

        player.sendPacket(Protocol.U_XING_YOU_SHAN_SHUI_RECOVER_ENERGY, rep.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
